﻿#region File Header
/***********************************************************************
 * Copyright © 2013 Beals Software
 * All Rights Reserved
************************************************************************
Author: Donald Beals
Date: February 4th, 2013
Description: TODO: Write a description of this file here.
****************************** Change Log ******************************
02.04.13 - Created initial file. (dbeals)
***********************************************************************/
#endregion

#region Using Statements
using System;

#endregion

namespace GameJolt.Requests
{
	/// <summary>
	/// 
	/// </summary>
	internal sealed class RequestParameter
	{
		#region Variables
		internal static readonly string GameIDKey = "game_id";
		internal static readonly string UsernameKey = "username";
		internal static readonly string UserTokenKey = "user_token";
		internal static readonly string UserIDKey = "user_id";
		internal static readonly string TrophyIDKey = "trophy_id";
		internal static readonly string StatusKey = "status";
		internal static readonly string KeyKey = "key";
		internal static readonly string DataKey = "data";
		internal static readonly string OperationKey = "operation";
		internal static readonly string ValueKey = "value";
		internal static readonly string ScoreKey = "score";
		internal static readonly string SortKey = "sort";
		internal static readonly string GuestKey = "guest";
		internal static readonly string ExtraDataKey = "extra_data";
		internal static readonly string TableIDKey = "table_id";
		internal static readonly string LimitKey = "limit";
		#endregion

		#region Properties
		public string Name
		{
			get;
			private set;
		}

		public object Value
		{
			get;
			internal set;
		}
		#endregion

		#region Constructors
		public RequestParameter(string name, object value)
		{
			this.Name = name;
			this.Value = value;
		}
		#endregion

		#region Methods
		public override string ToString()
		{
			return string.Format("{0}={1}", Name, Value == null ? string.Empty : Value.ToString());
		}

		public static RequestParameter CreateGameID(string value)
		{
			return new RequestParameter(GameIDKey, value);
		}

		public static RequestParameter CreateUsername(string value)
		{
			return new RequestParameter(UsernameKey, value);
		}

		public static RequestParameter CreateUserToken(string value)
		{
			return new RequestParameter(UserTokenKey, value);
		}

		public static RequestParameter CreateUserID(params string[] value)
		{
			return new RequestParameter(UserIDKey, string.Join(",", value));
		}

		public static RequestParameter CreateTrophyID(params string[] value)
		{
			return new RequestParameter(TrophyIDKey, string.Join(",", value));
		}

		public static RequestParameter CreateStatus(SessionStatus value)
		{
			return new RequestParameter(StatusKey, value.ToString().ToLower());
		}

		public static RequestParameter CreateKey(string value)
		{
			return new RequestParameter(KeyKey, value);
		}

		public static RequestParameter CreateData(string value)
		{
			return new RequestParameter(DataKey, value);
		}

		public static RequestParameter CreateOperation(DataStoreOperation value)
		{
			return new RequestParameter(OperationKey, value.ToString().ToLower());
		}

		public static RequestParameter CreateValue(object value)
		{
			return new RequestParameter(ValueKey, value);
		}

		public static RequestParameter CreateScore(object value)
		{
			return new RequestParameter(ScoreKey, value);
		}

		public static RequestParameter CreateSort(object value)
		{
			return new RequestParameter(SortKey, value);
		}

		public static RequestParameter CreateGuest(string value)
		{
			return new RequestParameter(GuestKey, value);
		}

		public static RequestParameter CreateExtraData(string value)
		{
			return new RequestParameter(ExtraDataKey, value);
		}

		public static RequestParameter CreateTableID(string value)
		{
			return new RequestParameter(TableIDKey, value);
		}

		public static RequestParameter CreateLimit(int value)
		{
			if(value < 0 || value > 100)
				throw new ArgumentOutOfRangeException(string.Format("{0} is out of the range for a limit parameter (1-100.)", value));
			return new RequestParameter(LimitKey, value);
		}
		#endregion
	}
}
